import request from '@/utils/request'

export function createMenu (data: object) {
  return request({
    url: 'boss/menu/saveOrUpdate',
    method: 'post',
    data
  })
}

// 菜单管理 =》获取编辑菜单页面信息
export function getEditMenuInfo (id = -1) {
  return request({
    url: 'boss/menu/getEditMenuInfo',
    method: 'get',
    params: { id }
  })
}

// 菜单管理 =》获取所有菜单
export function getMenuAll () {
  return request({
    url: '/boss/menu/getAll',
    method: 'get'
  })
}

// 删除菜单
export function deleteMenu (id: string) {
  return request({
    url: `/boss/menu/${id}`,
    method: 'delete'
  })
}

// 查询菜单
export function getMenu (id: string | number) {
  return request({
    url: `/boss/menu/${id}`,
    method: 'get'
  })
}

// 获取所有菜单并按层级展示
export function getMenuNodeList () {
  return request({
    url: '/boss/menu/getMenuNodeList',
    method: 'get'
  })
}

// 给角色分配菜单
export function allocateRoleMenus (data: object) {
  return request({
    url: '/boss/menu/allocateRoleMenus',
    method: 'post',
    data
  })
}

// 获取角色拥有的菜单列表
export function getRoleMenus (roleId: string | number) {
  return request({
    url: '/boss/menu/getRoleMenus',
    method: 'get',
    params: { roleId }
  })
}
